package org.x.user.controller;

import com.mybatisflex.core.paginate.Page;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.x.common.config.Result;
import org.x.common.enums.LogAsync;
import org.x.user.dto.AclQueryDTO;
import org.x.user.dto.CreateAclDTO;
import org.x.user.dto.UpdateAclDTO;
import org.x.user.entity.SysAclEntity;
import org.x.user.service.ISysAclService;
import org.x.user.vo.AclInfoVO;
import org.x.user.vo.AclVO;

/**
 * 权限表 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/api/acl")
public class SysAclController {

    @Autowired
    private ISysAclService sysAclService;

    /**
     * 创建权限点
     */
    @LogAsync("创建权限点")
    @PostMapping("/create")
    public Result create(@RequestBody @Valid CreateAclDTO aclDTO) {
        AclVO aclVO = sysAclService.createAcl(aclDTO);
        return Result.ok(aclVO);
    }
    /**
     * 更新权限点
     */
    @LogAsync("更新权限点")
    @PutMapping("/update")
    public Result updateAcl(@RequestBody @Valid UpdateAclDTO updateAclDTO) {
        AclVO aclVO = sysAclService.updateAcl(updateAclDTO);
        return Result.ok(aclVO);
    }
    /**
     * 删除权限点
     */
    @LogAsync("删除权限点")
    @DeleteMapping("/delete/{id}")
    public Result deleteAcl(@PathVariable("id") Long  id) {
        AclVO aclVO = sysAclService.deleteAcl(id);
        return Result.ok(aclVO);
    }
    /**
     * 查询权限点(分页)
     */
    @LogAsync("查询权限点")
    @GetMapping("/list")
    public Result list(@ModelAttribute @Valid AclQueryDTO aclQueryDTO) {
        Page<AclInfoVO> page = sysAclService.pageList(aclQueryDTO);
        return Result.ok(page);
    }
    /**
     * 查询权限点详情
     */
    @LogAsync("查询权限点详情")
    @GetMapping("/detail")
    public Result detail(@RequestParam Long id) {
        SysAclEntity sysAclEntity = sysAclService.getDetail(id);
        return Result.ok(sysAclEntity);
    }

}